import numpy as np

from conf.enum import OrderDir
from datetime import datetime as datetime_


class Engine:
    def __init__(self):
        pass


class Data:
    def __init__(self, variable_value):
        self.factor_ins = None
        self.variable_value = variable_value
        self.name = self.variable_value["lab_var_part2_2"]["show_data"]
        self.path = None

        self.com_data = None  # 全量数据
        self.ori_data = None  # 原始数据
        self.group_cont = []  # 用于存放多进程分割数据的容器
        pass


class Tactic:
    def __init__(self):
        self.name = ""
        self.describe = ""
        self.tactic_type = None
        self.factor_name = []  # 将用到的factor的名字传入

        self.bt_task = None  # 关联到backtest实例，进而获取到idx和factor_line

        self.idx = None
        pass


class Factor:
    def __init__(self):
        """因子基础类，面向全量行情数据DataFrame，新增因子列"""
        self.com_data = None
        self.open = None
        self.high = None
        self.low = None
        self.close = None
        self.volume = None

        pass

    def link_com_data(self, com_data):
        self.com_data = com_data
        self.open = self.com_data['open']
        self.high = self.com_data['high']
        self.low = self.com_data['low']
        self.close = self.com_data['close']
        self.volume = self.com_data['volume']


class Order:
    def __init__(self, order_size=None, remark=None, order_dir=None, idx=None):
        self.idx = idx
        self.order_dir: OrderDir = order_dir
        self.order_datetime: datetime_ = None
        if self.order_dir in [OrderDir.BUY, OrderDir.LONG]:
            self.order_size: int = abs(order_size)  # 为零则意味着该订单令仓位清零
        elif self.order_dir in [OrderDir.SELL, OrderDir.SHORT]:
            self.order_size: int = -abs(order_size)
        elif self.order_dir in [OrderDir.REJECT]:
            self.order_size: int = 0
        elif self.order_dir in [OrderDir.PASS]:
            self.order_size: int = 0
        elif self.order_dir is None:
            if order_size is None:
                raise ValueError("order_dir为None，order_size必须指定。")
            else:
                self.order_size = order_size
        else:
            raise ValueError("不支持的订单方向")
        self.remark = remark


